<?php

class MultilangConfig extends \Pinenut\Config {
	static $config = [
		'en' => [
			'default' => true,
			'title' => 'English',
			'accept' => ['en', 'en-us'],
		],
		'ru' => [
			'title' => 'Russian',
			'accept' => ['ru', 'ru-ua'],
		]
	];

	public static function initialize()
	{
		static::$config['en']['pluralInfo'] = [
			'size' => 2,
			'getPluralIndex' => function ($n){
				return $n != 1 ? 1 : 0;
			},
		];

		static::$config['ru']['pluralInfo'] = [
			'size' => 3,
			'getPluralIndex' => function ($n){
				return $n % 10==1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
			},
		];
	}

	public static function getDataForSelect() {

		$result = [];
		foreach (static::$config as $langId => $langInfo) {
			$result[$langId] = $langInfo['title'];
		}

		return $result;
	}

	public static function getDefaultLanguageCode()
	{
		foreach (static::$config as $langId => $langInfo)
		{
			if (isset($langInfo['default']) && $langInfo['default'] === true) {
				return $langId;
			}
		}

		throw new Exception('Default language is not set in MultilangConfig.');
	}

	public static function getLanguageCodes()
	{
		return array_keys(static::get());
	}
}